<!DOCTYPE html>
<!--
Copyright (c) 2016 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/extras/chrome/blame_context/blame_context.html">

<script>
'use strict';

/**
 * @fileoverview Trace Viewer side's correspondence of Chrome's
 * content::FrameBlameContext class.
 *
 */
tr.exportTo('tr.e.chrome', function() {
  const BlameContextSnapshot = tr.e.chrome.BlameContextSnapshot;
  const BlameContextInstance = tr.e.chrome.BlameContextInstance;

  function RenderFrameSnapshot() {
    BlameContextSnapshot.apply(this, arguments);
  }

  RenderFrameSnapshot.prototype = {
    __proto__: BlameContextSnapshot.prototype,

    referencedAt(item, object, field) {
      if (item instanceof tr.e.chrome.FrameTreeNodeSnapshot &&
          object === item.args &&
          field === 'renderFrame') {
        this.args.frameTreeNode = item;
      }
    },

    get frameTreeNode() {
      if (this.args.frameTreeNode instanceof
          tr.e.chrome.FrameTreeNodeSnapshot) {
        return this.args.frameTreeNode;
      }
      return undefined;
    },

    get url() {
      if (this.frameTreeNode) {
        return this.frameTreeNode.url;
      }
      return undefined;
    },

    get userFriendlyName() {
      return 'RenderFrame';
    }
  };

  tr.model.ObjectSnapshot.subTypes.register(
      RenderFrameSnapshot,
      {typeName: 'RenderFrame'});

  function RenderFrameInstance() {
    BlameContextInstance.apply(this, arguments);
  }

  RenderFrameInstance.prototype = {
    __proto__: BlameContextInstance.prototype,

    get blameContextType() {
      return 'Frame';
    }
  };

  tr.model.ObjectInstance.subTypes.register(
      RenderFrameInstance,
      {typeName: 'RenderFrame'});

  return {
    RenderFrameSnapshot,
    RenderFrameInstance,
  };
});
</script>
